home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F28138_SpokenLanguages.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-05  |  3.6 KB  |  96 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Category:       XSLT
  4.   Sub-category:   xsl:otherwise
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8.   Description:-
  9.     This stylesheet demonstrates the use of xsl:otherwise to
  10.     display a value if none of the tests in an xsl:choose equates
  11.     to true.  In this example, if none of the language
  12.     translation tests equates to true, the xsl:otherwise is
  13.     performed to display "English" as the spoken language.
  14.  =============================================================== -->
  15. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  16.   <xsl:output method="html" />
  17.  
  18.   <xsl:template match="/">
  19.     <html>
  20.       <head>
  21.         <title>Stylesheet Example</title>
  22.         <style type="text/css"><![CDATA[
  23.         H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  24.         H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  25.         .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  26.         .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  27.         .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  28.         TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
  29.         TD {COLOR: darkblue; FONT-FAMILY: Arial}
  30.         TR { background-color: beige; }
  31.         BODY { background-color: beige; }
  32.         ]]></style>
  33.       </head>
  34.       <body>
  35.         <xsl:apply-templates />
  36.       </body>
  37.     </html>
  38.   </xsl:template>
  39.  
  40.   <!-- Template for "employees" elements -->
  41.   <xsl:template match="employees">
  42.     <h1>Employee listing showing programming and spoken languages</h1>
  43.     <table border="1">
  44.       <tr>
  45.         <th>Department</th>
  46.         <th>Name</th>
  47.         <th>Hourly Rate</th>
  48.         <th>Programming Language</th>
  49.         <th>Spoken Language</th>
  50.       </tr>
  51.       <xsl:for-each select="employee">
  52.         <tr>
  53.           <td>
  54.             <xsl:value-of select="department" />
  55.           </td>
  56.           <td>
  57.             <xsl:value-of select="employeename" />
  58.           </td>
  59.           <td>
  60.             <xsl:value-of select="hourlyrate" />
  61.           </td>
  62.           <td>
  63.             <xsl:value-of select="primarylanguage" />
  64.           </td>
  65.           <td>
  66.             <xsl:choose>
  67.               <xsl:when test="nativelanguage = 'EN'">
  68.                 <xsl:value-of select="'English'" />
  69.               </xsl:when>
  70.               <xsl:when test="nativelanguage = 'FR'">
  71.                 <xsl:value-of select="'French'" />
  72.               </xsl:when>
  73.               <xsl:when test="nativelanguage = 'SP'">
  74.                 <xsl:value-of select="'Spanish'" />
  75.               </xsl:when>
  76.               <xsl:when test="nativelanguage = 'TH'">
  77.                 <xsl:value-of select="'Thai'" />
  78.               </xsl:when>
  79.               <xsl:when test="nativelanguage = 'GR'">
  80.                 <xsl:value-of select="'German'" />
  81.               </xsl:when>
  82.               <xsl:otherwise>
  83.               <!-- The Otherwise clause will be processed when none of the tests
  84.                equates to a true value.  In this example, since the author
  85.                of the sample lives in the united states, we will default
  86.                the language to English if it does not match any of the defined
  87.                languages :) -->
  88.                 <xsl:value-of select="'English'" />
  89.               </xsl:otherwise>
  90.             </xsl:choose>
  91.           </td>
  92.         </tr>
  93.       </xsl:for-each>
  94.     </table>
  95.   </xsl:template>
  96. </xsl:stylesheet>